import 'package:flutter/material.dart';
import 'package:debug_panel_module/proxy/debug_proxy.dart';

class BaseUrlSwitch extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return BaseUrlSwitchState();
  }
}

class BaseUrlSwitchState extends State<BaseUrlSwitch> {
  List netEvList = ["release", "debug", "mock"];

  ///默认选中第一个
  String groupUrlValue = "release";

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Padding(
          padding: EdgeInsets.only(left: 10, top: 10),
          child: Text("网络环境切换",
              style: TextStyle(
                  color: Color(0xFF666666),
                  fontSize: 16,
                  fontWeight: FontWeight.bold)),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            _radioBox(0, netEvList[0]),
            _radioBox(1, netEvList[1]),
            _radioBox(2, netEvList[2]),
          ],
        ),
      ],
    );
  }

  ///单个radio
  _radioBox(int value, String title) {
    return Row(
      children: <Widget>[
        Radio(
            value: title,
            groupValue: groupUrlValue,
            onChanged: (value) {
              _updateGroupValue(value);
            }),
        Text(title)
      ],
    );
  }

  ///更新选中的value
  void _updateGroupValue(dynamic value) {
    setState(() {
      groupUrlValue = value;
    });

    DebugProxy().urlSwitch(value);
  }
}
